﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Ribbon.Core
{
    public delegate void RectValueChanged(object OldValue, object NewValue);

    public class Rect
    {
        public Rect(float x, float y, float width, float height)
        {
            this.Height = height;
            this.Width = width;
            this.X = x;
            this.Y = y;
        }


        float height;

        public float Height
        {
            get { return height; }
            set
            {
                float old = height;

                height = value;

                if (ValueChange != null)
                {
                    ValueChange(old, value);
                }
            }
        }

        float width;

        public float Width
        {
            get { return width; }
            set
            {
                float old = width;

                width = value;

                if (ValueChange != null)
                {
                    ValueChange(old, value);
                }
            }
        }

        float x;

        public float X
        {
            get { return x; }
            set
            {
                float old = x;

                x = value;

                if (ValueChange != null)
                {
                    ValueChange(old, value);
                }
            }
        }

        float y;

        public float Y
        {
            get { return y; }
            set
            {
                float old = y;

                y = value;

                if (ValueChange != null)
                {
                    ValueChange(old, value);
                }
            }
        }


        //public float Height { get; set; }

        //public float Width { get; set; }

        //public float X { get; set; }

        //public float Y { get; set; }

        public bool Contains(PointF pt)
        {
            if (pt.X >= X && pt.X <= X + Width)
            {
                if (pt.Y >= Y && pt.Y <= Y + Height)
                {
                    return true;
                }
            }

            return false;
        }

        public bool Contains(float x, float y)
        {
            if (x >= X && x <= X + Width)
            {
                if (y >= Y && y <= Y + Height)
                {
                    return true;
                }
            }
            return false;
        }

        internal event RectValueChanged ValueChange;

        public override string ToString()
        {
            return string.Format("X:{0} Y:{1} Width:{2} Height:{3}", this.X, this.Y, this.Width, this.Height);
        }
    }
}
